package com.atguigu;

import com.atguigu.bean.Person;
import com.atguigu.config.MainConfig;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * Hello world!
 *
 */
@SpringBootApplication
public class App {
    public static void main( String[] args ) {
        /*  这是基于配置文件的方式
        ApplicationContext ctx =  new ClassPathXmlApplicationContext("beans.xml");
        Person person = (Person) ctx.getBean("person");
        System.out.println(person);*/

        //注解的方式怎么用呢？
        ApplicationContext ctx = new AnnotationConfigApplicationContext(MainConfig.class);
        Person person = (Person) ctx.getBean(Person.class);
        System.out.println(person);


        String[] nameForType = ctx.getBeanNamesForType(Person.class);
        for (String name : nameForType) {
            //获得bean的名字
            System.out.println(name);
        }

    }
}

